package com.xbongbong.paas.toolbox.util;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.pro.constant.CommonConstant;
import com.xbongbong.pro.constant.I18nStringConstant;
import com.xbongbong.pro.enums.IntervalTypeEnum;
import com.xbongbong.saas.constant.StringConstant;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.Month;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Locale;
import java.util.Objects;
import java.util.TimeZone;

public final class DateUtil {
	private static final Logger LOG = LoggerFactory.getLogger(DateUtil.class);
	public static SimpleDateFormat SDF = new SimpleDateFormat(
			"yyyy-MM-dd HH:mm:ss");
	public static SimpleDateFormat SDF_NoFormat = new SimpleDateFormat(
			"yyyyMMddHHmmss");
	public static SimpleDateFormat SDFYMDHM = new SimpleDateFormat(
			"yyyy-MM-dd HH:mm");
	public static SimpleDateFormat SDFDate = new SimpleDateFormat("yyyy-MM-dd");
	public static SimpleDateFormat SDFDate_NoFormat = new SimpleDateFormat("yyyyMMdd");
	public static SimpleDateFormat SDFYears = new SimpleDateFormat("yyyy");
	public static SimpleDateFormat SDFTime = new SimpleDateFormat("HH:mm:ss");
	public static SimpleDateFormat SDFMonthDay = new SimpleDateFormat("MM-dd");
	public static SimpleDateFormat SDFMonth = new SimpleDateFormat("yyyy-MM");
	public static SimpleDateFormat SDFMonth_NoFormat = new SimpleDateFormat("yyyyMM");
	/**
	 * 只显示时分
	 */
	public static SimpleDateFormat SDFHour_Minutes = new SimpleDateFormat("HH:mm");

	// long
	public static long getLong() {
		Date dt = new Date();
		long nowtTme = dt.getTime();
		return nowtTme;
	}

	/**
	 * 获取当前到秒的时间戳
	 * @return
	 */
	public static long getNow() {
		return getLong()/1000;
	}

	public static long getLong(Date date) {
		if(date==null) {
            return 0;
        }
		
		return date.getTime();
	}
	
	public static long getLong(String dateString) {
		return getLong(dateString,SDFYMDHM);
	}
	
	public static long getLong(String dateString,SimpleDateFormat format) {
		if(StringUtil.isEmpty(dateString)) {
            return 0;
        }
		
		Date dt =getDate(dateString,format);
		if(dt == null) {
            return 0;
        }
		
		return dt.getTime();
	}
	
	public static long getLong(String dateString,String formatStr) {
		return getLong(dateString , new SimpleDateFormat(formatStr));
	}
	// int
	
	/**
	 * 获取当天00：00 ，东八区修正，与格林威治时间相差8个小时 28800秒
	 * @return
	 */
	public static int getTodayInt() {
		return getTodayInt(getInt())  ;
	}
	/**
	 * 获取当天00：00 ，东八区修正，与格林威治时间相差8个小时 28800秒
	 * @return
	 */
	public static int getTodayInt(int day) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTimeInMillis(day * 1000L);
		calendar.set(Calendar.HOUR_OF_DAY, 0);
		calendar.set(Calendar.MINUTE, 0);
		calendar.set(Calendar.SECOND, 0);
		return (int)(calendar.getTimeInMillis() / 1000L);
		//return (int)(day+28800) / 86400 * 86400 - 28800;
	}

	/**
	 * 获取当天23:59:59 ，东八区修正，与格林威治时间相差8个小时 28800秒
	 * @return
	 */
	public static int getTodayEndInt(int day) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTimeInMillis(day * 1000L);
		calendar.set(Calendar.HOUR_OF_DAY,23);
		calendar.set(Calendar.MINUTE,59);
		calendar.set(Calendar.SECOND,59);
		return (int)(calendar.getTimeInMillis() / 1000L);
	}

	public static int getInt() {
		return (int)(getLong()/1000);
	}
	public static int getInt(Date date) {
		return (int)(getLong( date)/1000);
	}
	
	public static int getInt(String dateString) {
		return (int)(getLong( dateString)/1000);
	}


	public static int getInt(Long date){
		return (int)(date/1000);
	}
	public static int getInt(String dateString,SimpleDateFormat format) {
		if(StringUtil.isEmpty(dateString)) {
            return 0;
        }
		
		return (int)( getLong( dateString,format)/1000) ;
	}
	public static int getInt(String dateString,String formatStr) {
		return getInt( dateString , new SimpleDateFormat(formatStr));
	}
	 
	public static int getNowSDFYears() {
		int years = 0;
		Date dt = new Date();
		String addtime = SDFYears.format(dt);
		years = StringUtil.stringToInteger(addtime, 0);
		return years;
	}
	
	// String
	
	public static String getString(SimpleDateFormat format) {
		Date dt = new Date();
		String addtime = format.format(dt);
		return addtime;
	}
	
	public static String getString(String formatStr) {
	 
		return getString(new SimpleDateFormat(formatStr));
	}

	public static String getString(Date dt,SimpleDateFormat format) {
		if (dt == null) {
            return null;
        }

        return format.format(dt);
	}
	public static String getString(Date dt,String formatStr) {
		return  getString(dt,new SimpleDateFormat(formatStr));
	}
	public static String getString(Long datetime,SimpleDateFormat format) {
		if(datetime == null) {
            return null;
        }
		
		if(datetime == 0) {
            return "";
        }
		
		Date dt = new Date(datetime);
        return format.format(dt);
	}
	
	public static String getString(Long datetime,String formatStr) {
		return  getString(datetime,new SimpleDateFormat(formatStr));
	}
	
	public static String getString(Integer time,SimpleDateFormat format) {
		if(time == null) {
            return null;
        }
		return getString(1000L*time,format);
	}
	
	public static String getString(Integer time,String formatStr) {
		return  getString(time,new SimpleDateFormat(formatStr));
	}
	
	
	public static String getString() {
		return getString(SDFYMDHM);
	}

//	public static String getString(Date dt) {
//		return getString(  dt,SDFYMDHM) ;
//	}
	public static String getString(Date dt) {
		return getString(  dt,SDF) ;
	}
	
	public static String getString(long time) {
		return getString(time,SDFYMDHM);
	}
	
	public static String getString(int time) {
		return getString(time,SDFYMDHM);
	}
	 
	public static String getDateString(int time) {
		return getString(time,SDFDate);
	}
	public static String getDateString(Date time) {
		return getString(time,SDFDate);
	}
	
	public static String getLeftTime(int startTime,int limitTime) {
		String leftTime = null;
		Integer now = DateUtil.getInt();
		Integer differenceTime = now - startTime;
		if(differenceTime>=0){
			Integer leftTimeInt = limitTime - differenceTime;
			if(leftTimeInt<0){
				leftTimeInt = 0;
			}
			String h = (leftTimeInt/3600)+"";
			String m = (leftTimeInt%3600)/60+"";
			leftTime = h+ I18nMessageUtil.getMessage(CommonConstant.HOUR)+m+I18nMessageUtil.getMessage(CommonConstant.MINUTE);
		}
		return leftTime;
	}
	
	// date
	public static Date getDate(Long time) {
		if(time == null ) {
            return null;
        }
		return new Date(time);

	}
	public static Date getDate(Integer time) {
		if(time == null) {
            return null;
        }
		
		return new Date(1000L*time);
	}
	public static Date getDate( ) {
		return new Date();
	}
	
	public static Date getDate(String dateString,SimpleDateFormat format) {
		try {
			if(StringUtil.isEmpty(dateString)){
				dateString = getDateString(0);
				 
			}
			Date d = format.parse(dateString);
			return d;
		} catch (ParseException e) {
			e.printStackTrace();
			return null;
		}
	}

	public static Date getDate(String dateString ) {
		return getDate(  dateString, SDFYMDHM);
	}
	

	//获取当前年份1月1日0点0时0分
	public static final int getFirstDateOfYear(){
		return getFirstDateOfYear(getInt());
	}
	//获取当前年份12月31日24点24时24分 即 下一年的1月1日0点0时0分
	public static final int getLastDateOfYear(){
		return getLastDateOfYear(getInt());
	}
	//获取当前年份1月1日0点0时0分
	public static final int getFirstDateOfYear(Integer someday){
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(new Date((long)(someday) * 1000));
		calendar.set(calendar.get(Calendar.YEAR), 0, 1,0,0,0);
		return (int)(( calendar.getTimeInMillis())/1000);
	}
	
	//获取前一年的1月1日0点0时0分
	public static final int getFirstDateOfPreviousYear(){
		return getFirstDateOfPreviousYear(getInt());
	}
	
	//获取前一年的1月1日0点0时0分
	public static final int getFirstDateOfPreviousYear(Integer someday){
		Calendar calendar = Calendar.getInstance();

		calendar.setTime(new Date( (long)(someday)* 1000));
		calendar.set(calendar.get(Calendar.YEAR)-1, 0, 1,0,0,0);
		return (int)(( calendar.getTimeInMillis())/1000);
	}
	
	//获取当前年份12月31日24点24时24分 即 下一年的1月1日0点0时0分
	public static final int getLastDateOfYear(Integer someday){
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(new Date((long)(someday) * 1000));
		calendar.set(calendar.get(Calendar.YEAR)+1, 0, 1,0,0,0);
		return (int)(( calendar.getTimeInMillis())/1000);
	}
	
	public static final int getLastDateOfFirstSeason(){
		return getLastDateOfFirstSeason(getInt());
	}
	//获取当前年份第一季度结束时间
	public static final int getLastDateOfFirstSeason(Integer someday){
		Calendar calendar = Calendar.getInstance();
		
		calendar.setTime(new Date( (long)(someday)* 1000));
		calendar.set(calendar.get(Calendar.YEAR), 3, 1,0,0,0);
		return (int)(( calendar.getTimeInMillis())/1000);
	}

	// 获取某一天零点的时间戳
	public static long getZero4SomeDay(long timestamp) {
		return timestamp - (timestamp + 8 * 3600) % 86400;
	}
	
	/** 
	 *  
	 * 1 第一季度 2 第二季度 3 第三季度 4 第四季度 
	 *  
	 * @param someday
	 * @return 
	 */  
	public static int getSeason(Integer someday) {  

		int season = 0;  

		Calendar calendar = Calendar.getInstance();  
		calendar.setTime(new Date((long)(someday) * 1000)); 
		int month = calendar.get(Calendar.MONTH);  
		switch (month) {  
		case Calendar.JANUARY:  
		case Calendar.FEBRUARY:  
		case Calendar.MARCH:  
			season = 1;  
			break;  
		case Calendar.APRIL:  
		case Calendar.MAY:  
		case Calendar.JUNE:  
			season = 2;  
			break;  
		case Calendar.JULY:  
		case Calendar.AUGUST:  
		case Calendar.SEPTEMBER:  
			season = 3;  
			break;  
		case Calendar.OCTOBER:  
		case Calendar.NOVEMBER:  
		case Calendar.DECEMBER:  
			season = 4;  
			break;  
		default:  
			break;  
		}  
		return season;  
	}  
	
	/** 
	 *  
	 * 获得当前季度的第一天
	 *  
	 * @param someday
	 * @return 
	 */  
	public static int getFirstDateOfSeason(Integer someday) {  
		int m = 0;

		Calendar calendar = Calendar.getInstance();  
		calendar.setTime(new Date((long)(someday) * 1000)); 
		int month = calendar.get(Calendar.MONTH);  
		switch (month) {  
		case Calendar.JANUARY:  
		case Calendar.FEBRUARY:  
		case Calendar.MARCH:  
			m = 0;  
			break;  
		case Calendar.APRIL:  
		case Calendar.MAY:  
		case Calendar.JUNE:  
			m = 3;  
			break;  
		case Calendar.JULY:  
		case Calendar.AUGUST:  
		case Calendar.SEPTEMBER:  
			m = 6;  
			break;  
		case Calendar.OCTOBER:  
		case Calendar.NOVEMBER:  
		case Calendar.DECEMBER:  
			m = 9;  
			break;  
		default:  
			break;  
		}  
		calendar.set(calendar.get(Calendar.YEAR), m, 1,0,0,0);
		return (int)(( calendar.getTimeInMillis())/1000);  
	}  
	
	/** 
	 *  
	 * 获得当前季度的最后一天
	 *  
	 * @param someday
	 * @return 
	 */  
	public static int getLastDateOfSeason(Integer someday) {  
		int m = 0;

		Calendar calendar = Calendar.getInstance();  
		calendar.setTime(new Date((long)(someday) * 1000)); 
		int month = calendar.get(Calendar.MONTH);  
		switch (month) {  
		case Calendar.JANUARY:  
		case Calendar.FEBRUARY:  
		case Calendar.MARCH:  
			m = 3;  
			break;  
		case Calendar.APRIL:  
		case Calendar.MAY:  
		case Calendar.JUNE:  
			m = 6;  
			break;  
		case Calendar.JULY:  
		case Calendar.AUGUST:  
		case Calendar.SEPTEMBER:  
			m = 9;  
			break;  
		case Calendar.OCTOBER:  
		case Calendar.NOVEMBER:  
		case Calendar.DECEMBER:  
			m = 0;  
			break;  
		default:  
			break;  
		} 
		int year = calendar.get(Calendar.YEAR);
		//第四季度截止时间跨年问题
		if(m == 0) {
			year = year + 1;
		}
		calendar.set(year, m, 1,0,0,0);
		return (int)(( calendar.getTimeInMillis())/1000);    
	}
	
	//获取当前月份的1日0时0分0秒
	public static final int getFirstDateOfThisMonth(){
		Calendar calendar = Calendar.getInstance();   
		calendar.set(calendar.get(Calendar.YEAR),calendar.get(Calendar.MONTH),1,0,0,0);
		return (int)(( calendar.getTimeInMillis())/1000);
	}
	//获取某天所在月份的1日0时0分0秒
	public static final int getFirstDateOfMonthInSomeday(Integer someday){
		Calendar calendar = Calendar.getInstance();   
		calendar.setTime(new Date((long)(someday) * 1000));
		calendar.set(calendar.get(Calendar.YEAR),calendar.get(Calendar.MONTH),1,0,0,0); 
		return (int)(( calendar.getTimeInMillis())/1000);
	}
	
	/**
	 * 同比， 获取上年同月的第一天
	 * 比如传入的时间是2016年6月，则该方法得到2015年6月1日0时0分0秒
	 * @param someday
	 * @return
	 */
	public static final int getFirstDateOfLastYear(Integer someday){

		Calendar calendar = Calendar.getInstance();

		calendar.setTime(new Date( (long)(someday)* 1000));
		calendar.set(calendar.get(Calendar.YEAR)-1, calendar.get(Calendar.MONTH), 1,0,0,0);
		return (int)(( calendar.getTimeInMillis())/1000);
	}
	/**
	 * 同比，获取上年同月的最后一天
	 * 比如传入的时间是2016年6月，则该方法得到2015年7月1日0时0分0秒（即6月末）
	 * @param someday
	 * @return
	 */
	public static final int getLastDateOfLastYear(Integer someday){
		
		Calendar calendar = Calendar.getInstance();
		
		calendar.setTime(new Date( (long)(someday)* 1000));
		calendar.set(calendar.get(Calendar.YEAR)-1, calendar.get(Calendar.MONTH)+1, 1,0,0,0);
		return (int)(( calendar.getTimeInMillis())/1000);
	}
	
	//获取某天所在月份下个月的1日0时0分0秒
	public static final int getLastDateOfMonthInSomeday(Integer someday){
		Calendar calendar = Calendar.getInstance();   
		calendar.setTime(new Date((long)(someday) * 1000));
		calendar.set(calendar.get(Calendar.YEAR),calendar.get(Calendar.MONTH) + 1,1,0,0,0);    
		return (int)(( calendar.getTimeInMillis())/1000);
	}
	
	//获取当前月份的上一个月份的1日0时0分0秒
	public static final int getFirstDateOfLastMonth(){
		Calendar calendar = Calendar.getInstance();   
		calendar.set(calendar.get(Calendar.YEAR),calendar.get(Calendar.MONTH) - 1,1,0,0,0);   
		return (int)(( calendar.getTimeInMillis())/1000);
	}
	
	//获取某天所在月份的上一个月份的1日0时0分0秒
	public static final int getFirstDateOfLastMonth(Integer someday){
		Calendar calendar = Calendar.getInstance();   
		calendar.setTime(new Date((long)(someday) * 1000));
		calendar.set(calendar.get(Calendar.YEAR),calendar.get(Calendar.MONTH) - 1,1,0,0,0);   
		return (int)(( calendar.getTimeInMillis())/1000);
	}
	
	//获取当前月份的最后一天的24时24分24秒 即 下一个月的1日0时0分0秒
	public static final int getLastDateOfThisMonth(){
		Calendar calendar = Calendar.getInstance();   
		calendar.set(calendar.get(Calendar.YEAR),calendar.get(Calendar.MONTH) + 1,1,0,0,0);   
		return (int)(( calendar.getTimeInMillis())/1000);
	}
	//获取某天所在月份的下一个月的最后一天的23时59分59秒 即 下两个个月的1日0时0分0秒
	public static final int getLastDateOfNextMonthInSomeday(Integer someday){
		Calendar calendar = Calendar.getInstance();  
		calendar.setTime(new Date((long)(someday) * 1000));
		calendar.set(calendar.get(Calendar.YEAR),calendar.get(Calendar.MONTH) + 2,1,0,0,0);   
		return (int)(( calendar.getTimeInMillis())/1000);
	}

	//获取今年2月1日的0时0分0秒     用于推算其他月份的时间
	public static final int getFirstDateOfFeb(){
		Calendar calendar = Calendar.getInstance();   
		calendar.set(calendar.get(Calendar.YEAR),1,1,0,0,0);   
		return (int)(( calendar.getTimeInMillis())/1000);
	}
	
	//获取今年3月1日的0时0分0秒     用于推算其他月份的时间
	public static final int getFirstDateOfMar(){
		Calendar calendar = Calendar.getInstance();   
		calendar.set(calendar.get(Calendar.YEAR),2,1,0,0,0);   
		return (int)(( calendar.getTimeInMillis())/1000);
	}

	//获得本周一0点时间 
	public static int getThisWeekMorning(){ 
		return getWeekMorningInSomeday(getInt()); 
	} 
	//获取某天所在周的周一的0点
	public static final int getWeekMorningInSomeday(Integer someday){ 
	    Calendar calendar = Calendar.getInstance();
		calendar.setTime(new Date((long)(someday) * 1000));
		calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DATE), 0, 0, 0);
		int day_of_week = calendar.get(Calendar.DAY_OF_WEEK) - 1;
		if (day_of_week == 0) {
			day_of_week = 7;
		}
		calendar.add(Calendar.DATE, -day_of_week + 1);
		return  (int) (calendar.getTimeInMillis()/1000); 
	}
	/**
	 * Description:获取某一天在一周内的最后一天
	 * @param someday
	 * @author 魏荣杰
	 * @date 2018/3/21 19:03
	 * @since v3.19
	 * Modified by:
	 */
	public static final int getWeekLastDayInSomeday(Integer someday) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(new Date((long)(someday) * 1000));
		calendar.setFirstDayOfWeek(Calendar.MONTH);
		calendar.set(Calendar.DAY_OF_WEEK,	calendar.getFirstDayOfWeek() + 6);
		return (int) (calendar.getTimeInMillis() / 1000 + 86400);
	}
	//获取某天所在周是周几， 0-6,代表周日到周六
	public static final int getWeekInSomeday(Integer someday){ 
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(new Date((long)(someday) * 1000));
		Integer week = calendar.get(Calendar.DAY_OF_WEEK);
		return  week-1; 
	}

	//获取某个月有多少天
	public static final int getDaysOfSomeMonth(int someday){	
		Date date = new Date((long)(someday) * 1000);
		Calendar calendar = new GregorianCalendar();
		calendar.setTime(date);
		return calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
	}
	//获取某个月有多少周
	public static final int getWeeksOfSomeMonth(int someday){	
		Date date = new Date((long)(someday) * 1000);
		Calendar calendar = new GregorianCalendar();
		calendar.setTime(date);
		return calendar.getActualMaximum(Calendar.WEEK_OF_MONTH);
	}
	
	/**
	 * 获取当天是该月的第几周
	 * @param someday
	 * @return
	 */
	public static final int getWeekOfMonth(int someday) {
		Calendar calendar = Calendar.getInstance();   
		calendar.setTime(new Date((long)(someday) * 1000));
		return calendar.get(Calendar.WEEK_OF_MONTH);
	}
	
	/**
	 * 获取当天是该年的第几周
	 * @param someday
	 * @return
	 */
	public static final int getWeekOfYear(int someday) {
		Calendar calendar = Calendar.getInstance();   
		calendar.setTime(new Date((long)(someday) * 1000));
		return calendar.get(Calendar.WEEK_OF_YEAR);
	}
	
	//获得两个时间点之间跨度几月   例如：2015-5-12 2015-5-15 return 0
	public static final int getMonthBetweenSomeday(int startTime,int endTime){	
		Date startDate = new Date((long)(startTime) * 1000);
		Date endDate = new Date((long)(endTime) * 1000);
		int yearNum = endDate.getYear() - startDate.getYear();
		int monthNum = endDate.getMonth() - startDate.getMonth();
		return yearNum*12+monthNum;
	}
	
	
	//获得两个时间点之间跨度几季度   例如：2015-5-12 2015-5-15 return 0
	public static final int getSeasonBetweenSomeday(int startTime,int endTime){	
		Date startDate = new Date((long)(startTime) * 1000);
		Date endDate = new Date((long)(endTime) * 1000);
		int yearNum = endDate.getYear() - startDate.getYear();
		int seasonNum = getSeason(endTime) - getSeason(startTime);
		return yearNum*4+seasonNum;
	}
	
	//获得两个时间点之间跨度几年   例如：2015-5-12 2015-5-15 return 0
	public static final int getYearBetweenSomeday(int startTime,int endTime){	
		Date startDate = new Date((long)(startTime) * 1000);
		Date endDate = new Date((long)(endTime) * 1000);
		int yearNum = endDate.getYear() - startDate.getYear();
		return yearNum;
	}
	
	//获得两个时间点之间已满几个月
	public static final int getMonthNum(int startTime,int endTime){	
		Date startDate = new Date((long)(startTime) * 1000);
		Date endDate = new Date((long)(endTime) * 1000);
		int yearNum = endDate.getYear() - startDate.getYear();
		int monthNum = endDate.getMonth() - startDate.getMonth();
		int dayNum = endDate.getDate() - startDate.getDate();
		
		int ret = 0;
		if(dayNum<0){
			ret = yearNum*12+monthNum-1;
		}else{
			ret = yearNum*12+monthNum;
		}
		
		return ret;
	}
	
	//日程
	/**
	 * 返回年 如 2015
	 * @param time
	 * @return
	 */
	public static String getYear(Integer time) {
		if (time == null) {
			return null;
		}
		
		return getString(time).substring(0, 4);
	}
	/**
	 * 获取某个时间的年份
	 *
	 * @param someday 时间戳
	 * @return 年份
	 * @since performance-v1.0
	 * @version performance-v1.0
	 * @author chuanpeng.zhang
	 * 创建时间：2018年10月16日 下午5:31:58
	 * 修改时间：
	 */
	public static int getYear4Someday(Integer someday) {
		Calendar calendar = Calendar.getInstance();  
		calendar.setTime(new Date((long)(someday) * 1000)); 
		return calendar.get(Calendar.YEAR);
	}
	/**
	 * 返回月 如 04
	 * @param time
	 * @return
	 */
	public static String getMonth(Integer time) {
		if (time == null) {
			return null;
		}
		
		return getString(time).substring(5, 7);
	}
	/**
	 * 获取某个时间的月份
	 *
	 * @param someday 时间戳
	 * @return 月份
	 * @since performance-v1.0
	 * @version performance-v1.0
	 * @author chuanpeng.zhang
	 * 创建时间：2018年10月16日 下午5:30:34
	 * 修改时间：
	 */
	public static int getMonth4Someday(Integer someday) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(new Date((long)(someday) * 1000)); 
		return calendar.get(Calendar.MONTH) + 1;
	}
	/**
	 * 返回日 如 14
	 * @param time
	 * @return
	 */
	public static String getDay(Integer time) {
		if (time == null) {
			return null;
		}
		
		return getString(time).substring(8, 10);
	}
	/**
	 * 获取某个时间的日期
	 *
	 * @param someday 时间戳
	 * @return 日期
	 * @since performance-v1.0
	 * @version performance-v1.0
	 * @author chuanpeng.zhang
	 * 创建时间：2018年10月16日 下午5:33:15
	 * 修改时间：
	 */
	public static int getDay4Someday(Integer someday) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(new Date((long)(someday) * 1000)); 
		return calendar.get(Calendar.DAY_OF_MONTH);
	}
	/**
	 * 返回 HH:mm
	 * @param time time
	 * @return HH:mm
	 */
	public static String getHour(Integer time) {
		if (time == null) {
			return null;
		}
		
		return getString(time).substring(11);
	}
	
	//start + l毫秒
	public static Date addDate(Date start,long l) {
		
		return new Date(start.getTime()+l);

	}
	/**
	 * 获得一个前num个周一的日期数组，如：{"2015-4-26",...,"2015-3-15"}
	 * @param num
	 * @return
	 */
	public static String[] getWeekArray(Integer num){
		String[] weekArray = new String[num];
		Integer weekInt = getThisWeekMorning();
		
		for(int i = 0;i < num;i++){
			Integer week = weekInt - 86400*7*i;
			weekArray[i] = getDateString(week);
		}
		return weekArray;
	}
	/**
	 * 获得前num个月的1月1号，如：{"2015-4-1",......,"2014-1-1"}
	 * @param num
	 * @return
	 */
	public static String[] getMonthArray(Integer num){
		String[] monthArray = new String[num];
		int now = getInt();
		for(int i = 0;i < num;i++){
			now = getFirstDateOfLastMonth(now);
			monthArray[i] = getDateString(now);
		}
		return monthArray;
	}
	/**
	 * 获得前num年，如：{"2015",...,"2010"}
	 * @param num
	 * @return
	 */
	public static String[] getYearArray(Integer num){
		String[] yearArray = new String[num];
		Integer now = getInt();
		for(int i = 0;i < num;i++){
			now = getFirstDateOfPreviousYear(now);
			yearArray[i] = getString(now,SDFYears);
		}
		return yearArray;
	}
	
	/**
	 * 计算两个时间 相差天数
	 * @param beforeDay
	 * @param lastDay
	 * @return
	 */
	public static int betweenDays(int beforeDay, int lastDay) {
        int day = (lastDay - beforeDay) / (24 * 3600);
        /**----不返回小时数了----------*/
//        if (day == 0) {//小于一天的  按照小时
//            Calendar calendarB = Calendar.getInstance();
//            calendarB.setTime(getDate(beforeDay));
//            int hourB = calendarB.get(Calendar.HOUR_OF_DAY);
//            int dayB = calendarB.get(Calendar.DAY_OF_MONTH);
//
//            Calendar calendarL = Calendar.getInstance();
//            calendarL.setTime(getDate(lastDay));
//            int dayL = calendarL.get(Calendar.DAY_OF_MONTH);
//            int hourL = calendarL.get(Calendar.HOUR_OF_DAY);
//
////            day = dayL - dayB;
//            day = hourL - hourB;
//        }
        return day;
    }
	/**
	 * 获取两个时间点之间包含的周
	 * @param beforeDay
	 * @param lastDay
	 * @return
	 */
	public static int btweenWeeksByMonDay(int beforeDay, int lastDay){
		if(lastDay<beforeDay){
			return  0;
		}
		beforeDay = getWeekMorningInSomeday(beforeDay);//开始时间时间转为周一

		if(lastDay == getWeekMorningInSomeday(lastDay)){//周一
			if(lastDay == beforeDay){//同一天
				return 1;
			}else{
				return (lastDay-beforeDay)/(86400*7);
			}
		}else{
			if(beforeDay == getWeekMorningInSomeday(lastDay)){//同一周
				return 1;
			}else{
				return (lastDay-beforeDay)/(86400*7)+1;
			}
		}

	}

	public static int btweenMonthByFirst(int beforeDay, int lastDay){
		if(lastDay<beforeDay){
			return  0;
		}
		beforeDay = getFirstDateOfMonthInSomeday(beforeDay);//转成1号

		Calendar calendarB = Calendar.getInstance();
		calendarB.setTime(new Date((long)(beforeDay) * 1000));
		Calendar calendarL = Calendar.getInstance();
		calendarL.setTime(new Date((long)(lastDay) * 1000));

		if(lastDay == getFirstDateOfMonthInSomeday(lastDay)){//1号
			if(lastDay == beforeDay){//同一天
				return 1;
			}else{
				int year = calendarL.get(Calendar.YEAR)-calendarB.get(Calendar.YEAR);
				int month = calendarL.get(Calendar.MONTH)-calendarB.get(Calendar.MONTH);
				return year * 12 + month;
			}
		}else{
			if(beforeDay == getFirstDateOfMonthInSomeday(lastDay)){//同一月
				return 1;
			}else{
				int year = calendarL.get(Calendar.YEAR)-calendarB.get(Calendar.YEAR);
				int month = calendarL.get(Calendar.MONTH)-calendarB.get(Calendar.MONTH);
				return year * 12 + month + 1;
			}
		}
	}

	/**
	 * 
	 * @param lastConnectTime
	 * @param now
	 * @return
	 */
	public static int lastConnect(int lastConnectTime, int now) {
		int day = (now - lastConnectTime) / (24 * 3600);
		
		if (day == 0 && lastConnectTime < getTodayInt(now)) {
			return 1;
		}
		return day;
	}
	
	public static String getLastConnectTimeStr(Integer lastConnectTime){
		String lastConnectTimeStr = "";
		if (lastConnectTime == null || lastConnectTime == 0) {
			lastConnectTimeStr = I18nMessageUtil.getMessage(StringConstant.NEVER_CONNECT);
		}else {
			Integer flag = DateUtil.lastConnect(lastConnectTime , DateUtil.getInt());
			if (flag <= 0) {
				lastConnectTimeStr = I18nMessageUtil.getMessage(I18nStringConstant.CONTACTED_TODAY);
			}else if(flag <= 30){
				lastConnectTimeStr = flag + I18nMessageUtil.getMessage(I18nStringConstant.DAYS_NOT_CONNECTED);
			}else if(flag <= 30*2) {
				lastConnectTimeStr = I18nMessageUtil.getMessage(I18nStringConstant.NOT_CONTACTED_MORE_ONE_MONTH);
			}else if(flag <= 30*3) {
				lastConnectTimeStr = I18nMessageUtil.getMessage(I18nStringConstant.NOT_CONTACTED_MORE_TWO_MONTH);
			}else {
				lastConnectTimeStr = I18nMessageUtil.getMessage(I18nStringConstant.NOT_CONTACTED_MORE_THREE_MONTH);
			}
		}
		return lastConnectTimeStr;
	}
	
	//获取某时间点的这一年的第month个月的月初
	public static final int getFirstDateOfMonth(Integer someday,int month){
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(new Date((long)(someday) * 1000));
		calendar.set(calendar.get(Calendar.YEAR), month-1, 1,0,0,0);
		return (int)(( calendar.getTimeInMillis())/1000);
	}
	//获取某时间点的这一年的第month个月的月末
	public static final int getEndDateOfMonth(Integer someday,int month){
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(new Date((long)(someday) * 1000));
		calendar.set(calendar.get(Calendar.YEAR), month, 1,0,0,0);
		return (int)(( calendar.getTimeInMillis())/1000);
	}
	/**
	 * 获取excel里的时间格式，一般是1900年以来的天数 ，50000以内
	 * @param date
	 * @return
	 */
	public static Integer getExcelTime(String date){//获取excel中的格式各样的时间格式，统一格式解析
		Integer result=0;
		if(StringUtil.isEmpty(date)){
			return 0;
		}
		Integer dateInt=StringUtil.toInt(date);
		if(dateInt!=null && dateInt<50000)
		{
			result=(dateInt-25569)*86400-28800;
			if(dateInt==0){
				result=0;
			}
			 
			 
		}
		else{
		//excel中时间不是数字
			if(date.contains(".")){
				//2015.09.01格式
				date=date.replace(".", "-");
			}
			if(date.contains("/")){
				//2015/09/01格式
				date=date.replace("/", "-");
			}
			if(date.length()==8){
				//20150901格式
				date=date.substring(0,4)+"-"+date.substring(4, 6)+"-"+date.substring(6, 8);
			}
			if(date.contains("-")){
				try{
					result=DateUtil.getInt(date, DateUtil.SDFDate);
				}catch(Exception e){
					e.printStackTrace();
					result=0;
				}
				
			}
		}
		return result;
	}
	
	/**
	 * 获取某个时间的半年开始时间
	 * 比如，someday在前6个月，则该方法得到someday所在年的1月1日0点
	 * 		someday在后6个月，则该方法得到someday所在年的6月1日0点
	 * @param someday
	 * @return
	 * @author chuanpeng.zhang
	 * @time 2016-8-4 上午10:59:20
	 */
	public static int getHalfYearStartTime(Integer someday) {
        Calendar calendar = Calendar.getInstance();
		calendar.setTime(new Date((long)(someday) * 1000));
		int someMonth = calendar.get(Calendar.MONTH) + 1;
		
		Integer startTime = null;
		if (someMonth >= 1 && someMonth <= 6){
			startTime = getFirstDateOfMonth(someday, 1);
		}else if (someMonth >= 7 && someMonth <= 12){ 
			startTime = getFirstDateOfMonth(someday, 7);
		}
        
		return startTime;
	}
	/**
	 * 获取某个时间的半年结束时间
	 * 比如，someday在前6个月，则该方法得到someday所在年的6月30日24点--即7月1日0点
	 * 		someday在后6个月，则该方法得到someday所在年的12月31日24点--即下年的1月1日0点
	 * @param someday
	 * @return
	 * @author chuanpeng.zhang
	 * @time 2016-8-4 上午11:01:01
	 */
	public static int getHalfYearEndTime(Integer someday) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(new Date((long)(someday) * 1000));
		int someMonth = calendar.get(Calendar.MONTH) + 1;
		
		Integer endTime = null;
		if (someMonth >= 1 && someMonth <= 6){
			endTime = getEndDateOfMonth(someday, 6);
		}else if (someMonth >= 7 && someMonth <= 12){ 
			endTime = getEndDateOfMonth(someday, 12);
		}
		
		return endTime;
	}

	/**
	 * 输入原始Unix_Timestamp秒数，计算到今年的同一天
	 * 如得出用户今年的生日
	 *
	 * @param second 用户生日 Unix_Timestamp
	 * @return 用户今年的生日 Unix_Timestamp
	 */
	public static int formatOriginDay2ThisYear(int second) {
		SimpleDateFormat tempFormat = new SimpleDateFormat("yyyy-MM-dd");
		String bornDateStr = getString(new Date(second * 1000L), tempFormat);
		String todayDateStr = getString(new Date(), tempFormat);
		return getInt(todayDateStr.substring(0, 4) + bornDateStr.substring(4, bornDateStr.length()), tempFormat);
	}

	/**
	 * 输入原始Unix_Timestamp秒数，计算到今年的年数
	 * 如计算用户的年龄
	 *
	 * @param second
	 * @return
	 */
	public static int checkAge(int second) {
		Date originDate = DateUtil.getDate(second);
		Calendar born = Calendar.getInstance();
		Calendar birthday = Calendar.getInstance();

		born.setTime(originDate);
		birthday.setTime(new Date());

		// 年龄
		return birthday.get(Calendar.YEAR) - born.get(Calendar.YEAR);
	}

	/**
	 * 将秒数化为分钟
	 * @param seconds 秒数
	 * @return 分钟（向上取整）
	 *
	 * @author 章华隽
	 * 创建时间：2018/1/30 下午2:15
	 * 修改时间：
	 * @version 3.17
	 * @since 3.17
	 */
	public static Integer seconds2Minutes(Integer seconds) {
		int temp;
		if (seconds == null) {
			seconds = 0;
		} else {
			temp = seconds % 60;
			temp = temp > 0 ? 1 : 0;
			seconds = seconds / 60 + temp;
		}
		return seconds;
	}

	/**
	 * 校验时间字符串是否合法，合法则返回转化得到的10位Timestamp
	 *
	 * @param dateStr 	等待校验的时间字符串
	 *
	 * @return int 10位Timestamp
	 * @throws ParseException 时间格式转化异常
	 *
	 * @author 章华隽
	 * 创建时间： 2017/9/20 下午3:32
	 * 修改时间：
	 * @version
	 * @since 3.13
	 */
	public static int verifyDate(String dateStr) throws ParseException {
		return verifyDate(dateStr, null);
	}

	/**
	 * 校验时间字符串是否合法，合法则返回转化得到的10位Timestamp
	 *
	 * @param dateStr 	等待校验的时间字符串
	 * @param format 	时间字符串转换器
	 *
	 * @return int 10位Timestamp
	 * @throws ParseException 时间格式转化异常
	 *
	 * @author 章华隽
	 * 创建时间： 2017/9/20 下午3:32
	 * 修改时间：
	 * @version
	 * @since 3.13
	 */
	public static int verifyDate(String dateStr, SimpleDateFormat format) throws ParseException {
		if (StringUtil.isEmpty(dateStr)) {
			throw new ParseException("", 0);
		}
		if (format == null) {
			format = SDFDate;
		}
		// 指定日期格式为四位年/两位月份/两位日期，注意yyyy/MM/dd区分大小写；
		try {
			return getInt(format.parse(dateStr));
		} catch (ParseException e) {
			throw e;
		}
	}

	/**
	 * [yyyy-MM-dd格式]日期 +1天
	 * 例：dateStr="2018-01-31"，经过该方法处理，则返回"2018-02-01"
	 *
	 * @param dateStr [yyyy-MM-dd格式]，要加一天的日期
	 * @return [yyyy-MM-dd格式]日期
	 * @since 合同列表改造
	 * @version 
	 * @author lujiang
	 * 创建时间：when
	 * 修改时间：2018-1-31 上午9:48:37 by zcp
	 */
    public static String plusOneDay(String dateStr) {
        Date d = DateUtil.getDate(dateStr, new SimpleDateFormat("yyyy-MM-dd"));
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(d);
        //加一天
        calendar.add(Calendar.DAY_OF_MONTH, 1);

        return getDateString(calendar.getTime());
    }

	/**
	 * 获取当月的 天数
	 *
	 * @return 当月总天数
	 * @author 章华隽
	 * 创建时间：2018/3/28 下午2:52
	 * 修改时间：
	 * @version 3.20
	 * @since 3.20
	 */
	public static int getCurrentMonthDays() {
		Calendar c = Calendar.getInstance();
		c.set(Calendar.DATE, 1);
		c.roll(Calendar.DATE, -1);
		return c.get(Calendar.DATE);
	}
	/**
	 * 获取当前年份的天数
	 */
	public static int getCurrentYearDays() {
		Calendar date = Calendar.getInstance();
		Calendar c = Calendar.getInstance();
		c.set(Calendar.YEAR, date.get(Calendar.YEAR));
		return c.getActualMaximum(Calendar.DAY_OF_YEAR);
	}

	/**
	 * 获取上一年中当前日期的0点
	 * @return
	 * @author 梅伟丁
	 * @date 2022/4/21 18:11
	 * @version 1.0
	 */
	public static int getPastYear() {
		Calendar date = Calendar.getInstance();
		date.setTime(getDate());
		date.add(Calendar.YEAR, -1);
		date.set(Calendar.HOUR_OF_DAY, 0);
		date.set(Calendar.MINUTE, 0);
		date.set(Calendar.SECOND, 0);
		return getInt(date.getTime());
	}

	/**
	 * 获得下个月的天数
	 *
	 * @return 下个月的天数
	 */
	public int getMaxDayByYearMonth() {
		Calendar c = Calendar.getInstance();
		c.add(Calendar.MONTH, 1);
		c.set(Calendar.DATE, 1);
		c.roll(Calendar.DATE, -1);
		return c.get(Calendar.DATE);
	}

	/**
	 * 获取今天是几号
	 * @return 今天几号
	 *
	 * @author 章华隽
	 * 创建时间：2018/3/28 下午2:57
	 * 修改时间：
	 * @version 3.20
	 * @since 3.20
	 */
	public static int getTodayNumInMonth() {
		Calendar c = Calendar.getInstance();
		return c.get(Calendar.DATE);
	}

	/**
	 * 传入一个时间（someTime），计算该时间在财年的第几周
	 * 【如果周一在当前月份，则当周归属为该月，否则则归属到上一个月】
	 *
	 * @param startMonthTime 财年起始月第一天的时间戳
	 * @param someTime 时间戳
	 * @return someTime所在财年的第几周，如果是负数，则代表上一个财年的第几周
	 * @since
	 * @version
	 * @author 朱乾徽
	 * @date 2018/7/5 10:02
	 */
	public static int getWeekNum(Integer startMonthTime, Integer someTime) {
		//财年月第一周
		int weekNum = 0;
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(new Date((long)(startMonthTime) * 1000));
		//财年起始月第一天为周几
		int week = calendar.get(Calendar.DAY_OF_WEEK);
		//因为按照欧美，周日为一周第一天，所以为第几天需要进行判断
		if(week == 1) {
			week = 7;
		} else {
			week--;
		}
		//时间戳时间为周四时时间点为周四的0时0分0秒，所以实际时间需要减少一天
		if(week == 1) {
			//如果起始第一天为周一的话，第一周为当前财年的
			weekNum = (someTime - startMonthTime + (week - 1) * 3600 * 24) / 604800 + 1;
		} else {
			weekNum = (someTime - startMonthTime + (week - 1) * 3600 * 24) / 604800;
		}
		//如果当前的时间所属周在上一财年返回上一财年的最后一周为第几周(负数)
		if(weekNum == 0) {
			weekNum = -getWeekNum(getFirstDateOfLastYear(startMonthTime),someTime);
		}
		return weekNum;
	}
	/**
	 * 根据财年月的初始时间(startMonthTime)，获取第weekNum的周一0点的时间
	 *
	 * @param startMonthTime 财年起始月第一天的时间戳
	 * @param weekNum 第几周
	 * @return 第weekNum周的周一0点的时间戳
	 * @since
	 * @version
	 * @author 朱乾徽
	 * @date 2018/7/5 10:02
	 */
	public static Integer getWeekStartTime(int startMonthTime, int weekNum) {
		//第weekNum周的周一0点
		Integer weekStartTime = 0;
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(new Date((long)(startMonthTime) * 1000));
		//财年起始月第一天为周几
		int week = calendar.get(Calendar.DAY_OF_WEEK);
		//因为按照欧美，周日为一周第一天，所以为第几天需要进行判断
		if(week == 1) {
			week = 7;
		} else {
			week--;
		}
		if(weekNum > 0) {
			//如果财年第一天为周一，第一周为当前财年的
			if(week == 1) {
				weekStartTime = startMonthTime + (weekNum - 1) * 604800 - (week - 1) * 3600 * 24;
			} else {
				weekStartTime = startMonthTime + weekNum * 604800 - (week - 1) * 3600 * 24;
			}
		} else {
			//如果weekNum为负数时，为上一财年的时间，获取上一财年的第weekNum的时间戳
			weekStartTime = getWeekStartTime(getFirstDateOfLastYear(startMonthTime),-weekNum);
		}
		return weekStartTime;
	}
	/**
	 * 获取someday属于财年的第几季度
	 *
	 * @param someday 某一天
	 * @param startMonth 财年起始月
	 * @return
	 * @since 3.9
	 * @version 
	 * @author cp.zhang
	 * 创建时间：2017-7-12
	 * 修改时间：
	 */
	public static int getSeason4Fiscal(Integer someday, int startMonth) {
		Calendar calendar = Calendar.getInstance();  
		calendar.setTime(new Date((long)(someday) * 1000)); 
		int month = calendar.get(Calendar.MONTH);
		//calendar是从0开始的
		month ++;

		int season = 0;
		int beginMonth = startMonth;
		for (int i = 1; i <= 12; i++) {
			if (month == beginMonth) {
				//该值小于等于1代表第一个季度，以此类推
				double tempSeason = i/3.0;
				if (tempSeason <= 1) {
					season = 1;
				}else if (tempSeason <=2) {
					season = 2;
				}else if (tempSeason <=3) {
					season = 3;
				}else if (tempSeason <=4) {
					season = 4;
				}
				break;
			}
			
			beginMonth ++;
			//如果大于12，则从新从1月开始
			beginMonth = (beginMonth > 12)? 1: beginMonth;
		}
		return season;  
	}
	/**
	 * 判断当前月是在哪一个财年，例，当前7月，而财年周期是当年9月至次年8月，说明当前7月还在上一个财年
	 *
	 * @param startMonth 财年起始月
	 * @return 当前月所在财年
	 * @since 3.9
	 * @version 3.11.3
	 * @author cp.zhang
	 * 创建时间：2017-7-15 下午3:31:55
	 * 修改时间：2017-8-31 下午 by zcp 只要财年起始月不为1月，则当前财年为自然年+1
	 */
	public static Integer getFiscalYear4Now(int startMonth) {
		Integer nowTime = getInt();
		//当前年
		Integer year = getYear4Someday(nowTime);
		//当前月
		Integer month = getMonth4Someday(nowTime);
		return getFiscalYearByMonth(year, month, startMonth);
	}
	/**
	 * 根据月份判断year年所在的财年年份（只处理筛选自然时间的情况）
	 *
	 * @param year 筛选的自然年
	 * @param month 筛选的自然月
	 * @param startMonth 财年起始月份
	 * @return year年所在的财年年份
	 * @since performance-v1.0
	 * @version performance-v1.0
	 * @author chuanpeng.zhang
	 * 创建时间：2018年10月16日 下午4:29:14
	 * 修改时间：
	 */
	public static Integer getFiscalYearByMonth(Integer year, Integer month, int startMonth) {
		Integer fiscalYear = year;
		if (startMonth != 1 && month >= startMonth) {
			fiscalYear = year + 1;
		}
		return fiscalYear;
	}
	/**
	 * 获取筛选时间所在的财年年份
	 * 注：
	 * （1）该方法只适用于筛选了年度时，得到筛选的财年年份
	 * （2）当前系统财年所在年份即endTime所在的年份。
	 * @param startTime 筛选开始时间
	 * @param endTime 筛选截止时间
	 * @return 财年
	 * @since v3.19
	 * @version v3.19
	 * @author cp.zhang
	 * 创建时间：2018-3-13 下午3:23:32
	 * 修改时间：
	 */
	public static Integer getFiscalYearByTime(Integer startTime, Integer endTime) {
		return StringUtil.toInt(DateUtil.getYear(endTime - 86400));
	}
	/**
	 * 判断month月在财年内属于财年第几月
	 *
	 * @param startMonth 财年起始月
	 * @param month 自然月份
	 * @return month月在财年的第几月
	 * @since performance-v1.0
	 * @version performance-v1.0
	 * @author chuanpeng.zhang
	 * 创建时间：2018年9月5日 上午9:45:03
	 * 修改时间：
	 */
	public static Integer getFiscalMonth(int startMonth, int month) {
		if (startMonth == 1) {
			//起始月为1月，则跟自然月一致
			return month;
		}
		int fiscalMonth = (month + 12 - startMonth) % 12 + 1;
		return fiscalMonth;
	}
	/**
	 * 根据财年年份和财年月份获取出自然年份
	 *
	 * @param fiscalYear 财年年份
	 * @param fiscalMonth 财年月份
	 * @param startMonth 财年起始月份
	 * @return 自然年
	 * @since performance-v1.0
	 * @version performance-v1.0
	 * @author chuanpeng.zhang
	 * 创建时间：2018年10月17日 下午7:54:46
	 * 修改时间：
	 */
	public static Integer getNormalYearByFiscalYear(Integer fiscalYear, Integer fiscalMonth, int startMonth) {
		Integer year = fiscalYear;
		Integer month = getNormalMonthByFiscalMonth(fiscalMonth, startMonth);
		if (startMonth != 1 && month >= startMonth) {
			year = fiscalYear - 1;
		}
		return year;
	}
	/**
	 * 根据财年月份和财年起始月，得到自然月份
	 *
	 * @param fiscalMonth 财年月份
	 * @param startMonth 财年起始月份
	 * @return 自然月份
	 * @since performance-v1.0
	 * @version performance-v1.0
	 * @author chuanpeng.zhang
	 * 创建时间：2018年10月17日 下午8:27:26
	 * 修改时间：
	 */
	public static Integer getNormalMonthByFiscalMonth(int fiscalMonth, int startMonth) {
		if (startMonth == 1) {
			//起始月为1月，则跟自然月一致
			return fiscalMonth;
		}
		int month = (startMonth + fiscalMonth + 12) % 12 - 1;
		month = (month == 0)? 12: month;
		return month;
	}

	/**
	 * 将秒数转换为日时分秒，
	 * @param second
	 * @return
	 */
	public static String secondToTime(Integer second){
		second = second % 86400;            //剩余秒数
		long hours = second / 3600;            //转换小时
		second = second % 3600;                //剩余秒数
		long minutes = second /60;            //转换分钟
		second = second % 60;                //剩余秒数
		return hours + "时" + minutes + "分" + second + "秒";
	}

	/**
	 * 把秒数转为时间秒数文字：n秒，或者n分n秒，或者n时n分n秒
	 * @param second 总秒数
	 * @return java.lang.String
	 * @author zcp
	 * @date 2019/6/3 19:59
	 * @since v1.0
	 * @version v1.0
	 */
	public static String secondToTimeTip(Integer second){
		String timeTip = "0秒";
		if (second == null) {
		    return timeTip;
		}
		//剩余秒数
		second = second % 86400;
		//转换小时
		long hours = second / 3600;
		second = second % 3600;
		//转换分钟
		long minutes = second /60;
		//剩余秒数
		second = second % 60;
		if (hours > 0) {
			//达到小时，则格式化为“n时n分n秒”
			return hours + "时" + minutes + "分" + second + "秒";
		} else if (minutes > 0) {
			//未到1小时，则格式化为“n分n秒”
			return minutes + "分" + second + "秒";
		} else {
			//否则格式化为“n秒”
			return second + "秒";
		}
	}

	/**
	 * 根据时间分组类型格式化时间
	 * @param datetime 时间戳
	 * @param formatStr 格式化方式
	 * @return 格式化str结果
	 * @author zhouwq
	 * @date 2020/4/13 14:29
	 */
	public static String getStringByDateGroup(Long datetime, String formatStr) {
		if(datetime == null) {
			return null;
		}

		if(datetime == 0) {
			return "";
		}

		Date dt = new Date(datetime);
		String result;
		if (Objects.equals(formatStr, IntervalTypeEnum.YEAR_QUARTER.getFormat())) {
			LocalDateTime localDateTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(datetime),  ZoneOffset.systemDefault());
            return formatYearQuarterString(localDateTime.getYear(), localDateTime.getMonthValue());
		} else if (Objects.equals(formatStr, IntervalTypeEnum.YEAR_WEEK.getFormat())) {
			LocalDateTime localDateTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(datetime),  ZoneOffset.systemDefault());
			DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("w");
			String week = localDateTime.format(dateTimeFormatter);
			//当返回数据为12月 且是第一周时，代表跨年，year++
			int year = localDateTime.getMonthValue() == 12 && Objects.equals(week, "1") ? localDateTime.getYear() + 1 : localDateTime.getYear();
			return year + "年第" + week + "周";
		} else {
			result = new SimpleDateFormat(formatStr, Locale.CHINA).format(dt);
		}
		return result;
	}

	public static String getStringByDateGroup(Integer datetime, String formatStr) {
		return getStringByDateGroup(1000L * datetime, formatStr);
	}

	private static String formatYearQuarterString(int year, int month) {
		String quarter = "", result;
		if (month >= 1 && month <= 3) {
			quarter = "一季度";
		} else if (month >= 4 && month <= 6) {
			quarter = "二季度";
		} else if (month >= 7 && month <= 9) {
			quarter = "三季度";
		} else if (month >= 10 && month <= 12) {
			quarter = "四季度";
		}
		result = year + "年" + quarter;
		return result;
	}

	/**
	 * 获取季度末的时间戳
	 * @param date 季度初时间戳，应为1、4、7、10月初时间戳
	 * @return 季度末时间戳
	 * @author zhouwq
	 * @date 2020/4/13 15:25
	 */
	public static int getQuarterEndInt(Long date) {
		LocalDateTime localDateTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(date),  ZoneOffset.systemDefault());
		//季度末时间
		int month = localDateTime.getMonthValue() + 3;
		if (month > Month.DECEMBER.getValue()) {
			localDateTime = localDateTime.withMonth(1).withYear(localDateTime.getYear() + 1);
		} else {
			localDateTime = localDateTime.withMonth(month);
		}
		return (int)localDateTime.toEpochSecond(ZoneOffset.of("+8"));
	}

	public static int getQuarterEndInt(int date) {
		return getQuarterEndInt(date * 1000L);
	}

	/**
	 * 根据IntervalTypeEnum类型格式化时间，判断范围
	 * @param format 格式化类型
	 * @param dateTime 时间戳
	 * @return 格式化后的时间戳
	 * @author zhouwq
	 * @date 2020/6/19 14:28
	 */
	public static Long getTimeByIntervalType(String format, String dateTime) {
		long time;
		try {
			time = Long.parseLong(dateTime);
		} catch (NumberFormatException e) {
			return 0L;
		}
		LocalDateTime localDateTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(time),  ZoneOffset.systemDefault());
		LocalDateTime resultDateTime;
		IntervalTypeEnum intervalTypeEnum = IntervalTypeEnum.getByFormatStr(format);
		switch (intervalTypeEnum) {
			case YEAR:
				resultDateTime = LocalDateTime.of(localDateTime.getYear(), 1, 1, 0 ,0);
				break;
			case YEAR_WEEK:
				int week = localDateTime.getDayOfWeek().getValue();
				resultDateTime = LocalDateTime.of(localDateTime.getYear(), localDateTime.getMonth(), localDateTime.getDayOfMonth(), 0, 0).minusDays(week - 1);
				break;
			case YEAR_MONTH:
				resultDateTime = LocalDateTime.of(localDateTime.getYear(), localDateTime.getMonth(), 1, 0, 0);
				break;
			case YEAR_QUARTER:
				resultDateTime = LocalDateTime.of(localDateTime.getYear(), localDateTime.getMonth().firstMonthOfQuarter().getValue(), 1, 0, 0);
				break;
			default:
				resultDateTime = LocalDateTime.of(localDateTime.getYear(), localDateTime.getMonth(), localDateTime.getDayOfMonth(), 0, 0);
				break;
		}
		return resultDateTime.toEpochSecond(ZoneOffset.of("+8")) * 1000;
	}

		public static void main(String[] args) {
		System.out.println(getDateString(getInt()));
	}
}
